package nekocalc.gui.action;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JDialog;

import nekocalc.gui.AboutDialog;

public class NekoCalcMenuAction {
	//## FILE MENU ACTIONS ##//
	public Action fileQuit = null;
	//## EDIT MENU ACTIONS ##//
	public Action editCut = null;
	public Action editCopy = null;
	public Action editPaste = null;
	//## HELP MENU ACTIONS ##//
	public Action helpAbout = null;
	
	/**
	 * 	Unless usual classes members have their visibility set to <b>public</b>
	 * this will save us from creating getters. Moreover the goal of this class
	 * is to provide Action objects to be used with menus
	 * @author EminoMeneko
	 */
	public NekoCalcMenuAction() {
		//## FILE MENU ACTIONS ##//
		this.fileQuit = new FileQuitAction("Quit", new Integer(KeyEvent.VK_Q), "Quits the app !", "Allows you to terminate the application properly");
		
		//## FILE MENU ACTIONS ##//
		this.editCut = new EditCutAction("Cut", new Integer(KeyEvent.VK_CUT), "Cut value.", "Cuts the selected value.");
		this.editCopy = new EditCopyAction("Copy", new Integer(KeyEvent.VK_COPY), "Copy value.", "Copy the selected value.");
		this.editPaste = new EditPasteAction("Paste", new Integer(KeyEvent.VK_PASTE), "Paste value.", "Pastes the selected value.");
		
		//## FILE MENU ACTIONS ##//
		this.helpAbout = new HelpAboutAction("About...", new Integer(KeyEvent.VK_T), "Displays the About... dialog", "Displays the About dialog");
	}
	
	//## FILE MENU ACTIONS ##//
	class FileQuitAction extends AbstractAction {
		private ImageIcon icon = new ImageIcon(NekoCalcMenuAction.class.getResource("../../res/img/Quit.png"));
		
		public FileQuitAction(String text, Integer mnemonic, String shortDesc, String longDesc) {
			putValue(NAME, text);
			putValue(MNEMONIC_KEY, mnemonic);
			putValue(SMALL_ICON, icon);
			putValue(SHORT_DESCRIPTION, shortDesc);
			putValue(LONG_DESCRIPTION, longDesc);
		}
		
		public void actionPerformed(ActionEvent e) {
			System.exit(0);
		}
	}
	
	//## EDIT MENU ACTIONS ##//
	class EditCutAction extends AbstractAction {
		private ImageIcon icon = new ImageIcon(NekoCalcMenuAction.class.getResource("../../res/img/Cut.png"));
		
		public EditCutAction(String text, Integer mnemonic, String shortDesc, String longDesc) {
			putValue(NAME, text);
			putValue(MNEMONIC_KEY, mnemonic);
			putValue(SMALL_ICON, icon);
			putValue(SHORT_DESCRIPTION, shortDesc);
			putValue(LONG_DESCRIPTION, longDesc);
		}
		
		public void actionPerformed(ActionEvent e) {
			System.exit(0);
		}
	}

	class EditCopyAction extends AbstractAction {
		private ImageIcon icon = new ImageIcon(NekoCalcMenuAction.class.getResource("../../res/img/Copy.png"));
		
		public EditCopyAction(String text, Integer mnemonic, String shortDesc, String longDesc) {
			putValue(NAME, text);
			putValue(MNEMONIC_KEY, mnemonic);
			putValue(SMALL_ICON, icon);
			putValue(SHORT_DESCRIPTION, shortDesc);
			putValue(LONG_DESCRIPTION, longDesc);
		}
		
		public void actionPerformed(ActionEvent e) {
			System.exit(0);
		}
	}

	class EditPasteAction extends AbstractAction {
		private ImageIcon icon = new ImageIcon(NekoCalcMenuAction.class.getResource("../../res/img/Paste.png"));
		
		public EditPasteAction(String text, Integer mnemonic, String shortDesc, String longDesc) {
			putValue(NAME, text);
			putValue(MNEMONIC_KEY, mnemonic);
			putValue(SMALL_ICON, icon);
			putValue(SHORT_DESCRIPTION, shortDesc);
			putValue(LONG_DESCRIPTION, longDesc);
		}
		
		public void actionPerformed(ActionEvent e) {
			System.exit(0);
		}
	}
	

	
	//## HELP MENU ACTIONS ##//
	class HelpAboutAction extends AbstractAction {
		private ImageIcon icon = new ImageIcon(NekoCalcMenuAction.class.getResource("../../res/img/About.png"));
		
		public HelpAboutAction(String text, Integer mnemonic, String shortDesc, String longDesc) {
			putValue(NAME, text);
			putValue(MNEMONIC_KEY, mnemonic);
			putValue(SMALL_ICON, icon);
			putValue(SHORT_DESCRIPTION, shortDesc);
			putValue(LONG_DESCRIPTION, longDesc);
		}
		
		public void actionPerformed(ActionEvent e) {
			javax.swing.SwingUtilities.invokeLater( new Runnable() {
				public void run() {
					JDialog dialog = new AboutDialog();					
				}
			});
		}
	}
}
